class Solution {
    public boolean hasPathSum(TreeNode root, int targetSum) {
        //边界检查
        if(root == null){
            return false;
        }
        return recursionSum(root,targetSum,0);
    }

    public boolean recursionSum(TreeNode root, int targetSum, int currentSum) {
        currentSum  = currentSum + root.val;
        //结束条件
        if(root.left == null && root.right == null){
            if(currentSum == targetSum){
                return true;
            }else{
                return false;
            }
        }

        boolean flag = false;
        if(root.left != null){
            flag = recursionSum(root.left,targetSum,currentSum);
        }
        if(flag == true){
            return true;
        }
        if(root.right != null){
            flag = recursionSum(root.right,targetSum,currentSum);
        }
        return flag;

    }
}